package com.yanqu.road.server.logic.recharge.limit.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangUserFloor;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.server.gameplayer.module.activity.huashigang.HuaShiGangModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.huashigang.HuaShiGangMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

public class HuaShiGangActivityMallLimit extends BaseActivityMallLimit{
    public HuaShiGangActivityMallLimit(long userId, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(userId, mallInfo, activityInfo);
    }

    @Override
    protected int activityCheck() {
        if(!ActivityMgr.activityInTime(activityInfo)){
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        if(activityInfo.getType() != eActivityType.CrossHuaShiGangActivity.getValue()){
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        return 0;
    }

    @Override
    protected boolean isSystemUnLock() {
        return SystemOpenMgr.systemOpen(player, eSystemId.HuaShiGang.getValue());
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        LimitBuyResult limitBuyResult = new LimitBuyResult();
        ActivityInfo activityInfo = HuaShiGangMgr.getActivityInfo();
        int touchTimes = 0;
        if (ActivityMgr.activityInShowTime(activityInfo)) {
            HuaShiGangUserFloor userdata = player.getModule(HuaShiGangModule.class).getFloorData(activityInfo.getActivityId());
            if(null != userdata){
                touchTimes = userdata.getMallTimes(mallInfo.getMallId());
                if(userdata.getCurrentMall() == mallInfo.getMallId()){
                    touchTimes++;
                }
            }
        }
        limitBuyResult.setRet(0);
        limitBuyResult.setLimitCount(touchTimes);
        return limitBuyResult;
    }

    @Override
    protected int logicCheck() {
        if (!player.getModule(HuaShiGangModule.class).canPrecharge(mallInfo.getMallId())) {
            return GameErrorCode.E_MALL_LIMIT_BUY;
        }
        return 0;
    }
}
